package Collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class CollectionToArray {
    public static void main(String[] args) {
        Collection<String> c=new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        System.out.println(c);
        //集合转数组
        //若参数数组元素==集合个数那么正常转换
        //若参数数组元素<集合个数那么正常转换（按照集合大小给数组）
        //若参数数组元素>集合个数那么正常转换同时在末尾补默认值
        String[] array =c.toArray(new String[c.size()]);//等同于String
        String[] array1 =c.toArray(new String[0]);//<
        String[] array2 =c.toArray(new String[8]);//>
        System.out.println(Arrays.toString(array));
        System.out.println(Arrays.toString(array1));
        System.out.println(Arrays.toString(array2));


    }
}
